#ifndef _SKBOOKLIST_HPP_
#define _SKBOOKLIST_HPP_

#include "SKBookNode.hpp"


class SKBookList
{
public:
    struct SKBookListNode
    {
	SKBookListNode(SKBookNode* node = 0): next_(0), node_(node) {}
	
	SKBookListNode* next_;
	SKBookNode* node_;
    };

    SKBookList():front_(0), size_(0) {}

    //iterator
    class iterator
    {
    public:
	iterator(SKBookList* map, SKBookListNode* node): list_(map), node_(node) {}
	iterator(const iterator& iter): list_(iter.list_), node_(iter.node_) {}

	iterator& operator=(const iterator& iter)
	{
	    if (iter == *this)
		return *this;
	    list_ = iter.list_;
	    node_ = iter.node_;
	}

	bool operator==(const iterator& iter) const
	{
	    return (iter.node_ == node_);
	}

	bool operator!=(const iterator& iter) const
	{
	    return (iter.node_ != node_);
	}

	SKBookListNode* operator->()
	{
	    return node_;
	}

	SKBookListNode& operator*()
	{
	    return *node_;
	}

	iterator& operator++() // pre
	{
	    node_ = node_->next_;
	    return *this;
	}

	iterator operator++(int) //post
	{
	    if (!node_)
		return *this;
	    SKBookListNode* tmp = node_;
	    node_ = node_->next_;
	    return iterator(list_, tmp);
	}

    private:
	friend class SKBookList;
	SKBookList* list_;
	SKBookListNode* node_;
    };

    iterator begin();
    iterator end();
    SKBookListNode* createNode(SKBookNode* node);
    bool deleteNode(SKBookNode* node);
    void addNode(SKBookNode* node);
    void clear();
    ~SKBookList() { clear(); }

private:
    // first node
    SKBookListNode* front_;
    unsigned long size_;
};


#endif //_SKBOOKLIST_HPP_
